<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户中心</title>
    <link rel="stylesheet" th:href="@{/css/iconfont.css}"/>
    <link rel="stylesheet" th:href="@{/css/styles.css}"/>
    <header th:replace="header::html"></header>
</head>

<body>
<div class="header">
    <div class="bar">
        <div class="w1200">
            <span class="l">众包平台<font>用户中心</font></span>
            <span class="r"><a href="/api-front/getPage?pageName=index"><i class="icon iconfont icon-dianyuan"></i>返回主页</a></span>
        </div>
    </div>
    <div class="user-info">
        <div class="w1200">
            <div class="user-headface">
                <img th:src="@{/images/user_face.jpg}"/>
            </div>
            <div class="user-account">
                <input type="hidden" id="rid" th:value="${#authentication.principal.uid}">
                <p class="tip" th:text="'您好！  '+${#authentication.principal.uname}"></p>
                <p class="account">
                    <span th:text="'帐户名：'+${#authentication.principal.uaccount}"></span>
                    <span th:text="'用户：'+${#authentication.principal.uname}">用户：tomandjerry（数据库获取）</span>
                </p>
            </div>
            <div class="user-modify">
                <input type="button" value="充值" style="background:  #62ab00;color:  #fff;border-radius: 5px;width: 110px;height: 40px;" onclick="recharge()">

            </div>
        </div>
    </div>
</div>
<div class="main w1200">
    <div class="left">
        <ul id="allMenu">
        </ul>
    </div>
    <div class="right">
        <div class="tap">
            <span id="addPrompt">系统消息</span>
        </div>
        <div class="container">
            <div class="no-doc">
                <img id="imgP" th:src="@{/images/no_doc.jpg}"/>
                <p id="msg" style="display: block">您还没有消息哦~</p>
                <iframe src="" name="myframe" id="myframe" style="width: 100%;height: 100%" frameborder="0"></iframe>
            </div>
        </div>
    </div>
</div>
</body>
<script>
	window.onload = function () {
		var rid = document.getElementById("rid").value;
		$.ajax({
			type: 'GET',
			url: '/api-back/permission/menu',
			data: {'userId': rid},
			success: function (result) {
				var menu = result.data;
				for (var i = 0; i < menu.length; i++) {
					 // alert("name:" + menu[i].name + "src:" + menu[i].href);
					$('#allMenu').append('<li><a  title="' + menu[i].href + '" onclick="aClick(this)"><i class="icon iconfont icon-pinglun"></i>' + menu[i].name + '</a></li>');
				}
			}
		});
	};

	function aClick(node) {
		var path = node.title;
		// var path = node.getAttribute("title");
		var iframeNode = document.getElementById("myframe");
		iframeNode.src = path;
		var addPrompt = node.innerText;
		//alert(addPrompt);
		//点击设置span标签的内容
		document.getElementById('addPrompt').innerText = addPrompt;
		//点击a标签将图片和字体隐藏
		document.getElementById('msg').style.display = "none";
		document.getElementById('imgP').style.display = "none";
	}
    function recharge() {
        // alert("我要充值");
	    layer.prompt({
		    formType: 2,
		    title: '请输入您要充值的金额'
	    },function (value, index, elem) {
		    var msg1 = value.trim();
		   // msg1=msg1.replace(/^\d{1,4}$/,"输入金额只能1-9999");
		    if (!(msg1>=1&&msg1<=9999)){
		    	layer.alert("请输入金额1-9999",{icon: 5})
		    	//alert("请输入金额1-9999");
            }

            else{
	            $.ajax({
		            url: "/api-front/frontneed/charge",
		            type: "GET",
		            data: {msg: msg1},
		            dataType: 'text',
		            success: function (msg) {
			            if (msg === "yes") {
				            layer.alert("操作成功", {icon: 1}, function (index1) {
					            layer.close(index1);
                                window.location.href="/api-front/getPage?pageName=frontPage/personal"
				            });

			            } else {
				            layer.alert("操作失败", {icon: 1}, function (index1) {
					            layer.close(index1);

				            });

			            }
		            }
	            });

                layer.close(index);
            }
	    });

    }

</script>
</html>